import logging
from logging import handlers
from base.setting import setting
import time
import os


log_name = os.path.join(setting.log_path['path'], time.strftime('%Y-%m-%d', time.localtime()) + '-log.log')

def case_log():
    log_format = '%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s'
    logging.basicConfig(level=logging.DEBUG, format=log_format)
    logger = logging.getLogger()
    # 屏幕写入
    # th = logging.StreamHandler()
    # 文件输出
    format_str = logging.Formatter(log_format)
    sh = handlers.TimedRotatingFileHandler(filename=log_name, when='D', encoding='utf-8')
    sh.setFormatter(format_str)
    logger.addHandler(sh)
    # logger.addHandler(th)
    return logger


if __name__ == '__main__':
    log = case_log()
    log.debug('hello')